package service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import bean.Entity;
import config.MyBatisConfig;
import dao.EntityDAO;
import service.EntityService;

@Service(value = "service")
/*
 * @Import注解表示要导入的一个或多个组件类，通常是@Configuration类
 * 除@Import外，还可以使用@ComponentScan批量导入多个组件类
 */
@Import(value = MyBatisConfig.class)
public class EntityServiceImpl implements EntityService {
    @Autowired
    private EntityDAO dao;

    public void setDao(EntityDAO dao) {
        this.dao = dao;
    }

    @Override
    /*
     * 注解@Transactional作用于类时，表示这个注解作为默认值适用于声明类及其子类的所有方法
     */
    @Transactional
    public void add(String temp) {
        dao.addEntity(temp);
    }

    @Override
    @Transactional
    public void modify(Entity temp) {
        dao.modifyEntity(temp);
        
    }

    @Override
    @Transactional
    public void remove(int id) {
        dao.removeEntity(id);
    }

    @Override
    public Entity query(int id) {
        return dao.selectEntity(id);
    }

    @Override
    public List<Entity> queryByName(String keyword) {
        return dao.selectEntities(keyword);
    }
}
